package com.tiyende.kash.loop.ui.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.tiyende.kash.loop.R
import com.tiyende.kash.loop.common.CommonDialog
import com.tiyende.kash.loop.databinding.TiyendeDialogHttpErrorBinding
import com.tiyende.kash.loop.event.TiyendeEventPointType

/**
 * TiyendeCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/13 15:41
 * @Annotation：网络异常提示dialog
 */
class TiyendeHttpErrorDialog: CommonDialog {

    private lateinit var binding: TiyendeDialogHttpErrorBinding
    private var mCallback: IDialogCallback? = null
    //事件备注
    private var eventRemark = ""

    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context, remark: String) : super(context) {
        eventRemark = remark
    }
    constructor(context: Context, remark: String, callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getTiyendeRootView(): View {
        binding = TiyendeDialogHttpErrorBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initTiyendeView() {
    }

    override fun initTiyendeListener() {
        setOnClickListener(binding.btReload) //Reload
    }

    override fun loadTiyendeData() {
    }

    override fun onTiyendeViewClick(v: View?) {
        dismiss()
        when(v?.id){
            R.id.btReload -> {
                addEventPointRequestAction(TiyendeEventPointType.CLICK.TIYENDE_CLICK_REQUEST_ERROR_RELOAD,eventRemark)
                mCallback?.onTiyendeReloadClick()
            }
        }
    }

    /**
     * 设置埋点备注
     */
    fun addTiyendeTipsEventRemark(remark: String){
        eventRemark = remark
    }

    /**
     * 设置提示语
     */
    fun addTiyendeTipsText(tips: String){
        binding.txtErrorMsg.text = tips
    }

    interface IDialogCallback {
        //按钮点击
        fun onTiyendeReloadClick()
    }

    override fun onStart() {
        super.onStart()
        addEventPointRequestAction(TiyendeEventPointType.DIALOG.TIYENDE_DIALOG_REQUEST_ERROR_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        addEventPointRequestAction(TiyendeEventPointType.DIALOG.TIYENDE_DIALOG_REQUEST_ERROR_DISMISS,eventRemark)
    }
}